{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "killing-amsterdam",
   "metadata": {},
   "source": [
    "# visualize-timeseries-runchart"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f3cba135-fe00-45b1-b69d-163019e7c820",
   "metadata": {},
   "source": [
    "Plots a run chart of a time series (x time, y value)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "tribal-newcastle",
   "metadata": {},
   "outputs": [],
   "source": [
    "!pip3 install pandas==1.3.2 wget==3.2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "informed-bonus",
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import pandas as pd\n",
    "import json\n",
    "import logging\n",
    "import re\n",
    "import sys"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "encouraging-islam",
   "metadata": {},
   "outputs": [],
   "source": [
    "# CSV file to visualize\n",
    "data_csv = os.environ.get('data_csv', 'data.csv')\n",
    "\n",
    "# x - axis column name\n",
    "x_column = os.environ.get('x_column')\n",
    "\n",
    "# y - axis column name\n",
    "y_column = os.environ.get('y_column')\n",
    "\n",
    "# temporal data storage for local execution\n",
    "data_dir = os.environ.get('data_dir', '../../data/')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "387f9744-4ebd-4763-885d-38f8158466b6",
   "metadata": {},
   "outputs": [],
   "source": [
    "parameters = list(\n",
    "    map(lambda s: re.sub('$', '\"', s),\n",
    "        map(\n",
    "            lambda s: s.replace('=', '=\"'),\n",
    "            filter(\n",
    "                lambda s: s.find('=') > -1 and bool(re.match(r'[A-Za-z0-9_]*=[.\\/A-Za-z0-9]*', s)),\n",
    "                sys.argv\n",
    "            )\n",
    "    )))\n",
    "\n",
    "for parameter in parameters:\n",
    "    logging.warning('Parameter: ' + parameter)\n",
    "    exec(parameter)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "systematic-aruba",
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.read_csv(data_dir + data_csv)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "devoted-advertising",
   "metadata": {},
   "outputs": [],
   "source": [
    "df.plot(x=x_column, y=y_column)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d479c7d3-0f2c-4188-8100-63c4c5ffa5c6",
   "metadata": {},
   "outputs": [],
   "source": [
    "metadata = {\"outputs\": [{\"storage\": \"inline\", \"source\": \"# TEST AUC:xxxxxx \\n\\n#GBDT AUC:xxxxxxx\", \"type\": \"markdown\"}]}\n",
    "metadata = json.dumps(metadata)\n",
    "with open(\"/mlpipeline-ui-metadata.json\", \"w\") as text_file:\n",
    "    text_file.write(metadata)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
